package org.gluedom.marshall;

import java.util.Map;

import com.google.common.collect.MapMaker;

public class Marshallers {
	private Marshallers() {
		throw new AssertionError();
	}

	public static final String DEFAULT = "default";

	private static final Map<String, MarshallerFactory> factoryTable = new MapMaker()
			.makeMap();

	static {
		factoryTable.put("binary", new BinaryMarshallerFactory());
		factoryTable.put(DEFAULT, factoryTable.get("binary"));
	}

	public static void registerFactory(String name, MarshallerFactory factory) {
		factoryTable.put(name, factory);
	}

	public static void registerDefaultFactory(MarshallerFactory factory) {
		factoryTable.put(DEFAULT, factory);
	}

	public static Marshaller getMarshaller() {
		return getMarshaller(DEFAULT);
	}

	public static Marshaller getMarshaller(String name) {
		return factoryTable.get(name).getInstance();
	}
}
